package com.qq2008.game.mojie.interceptor;


import com.qq2008.game.mojie.conf.ServerConf;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

/**
 * 拦截器注册配置
 */
@Configuration
public class RegisterInterceptor extends WebMvcConfigurationSupport {

    /**
     * 提前注入bean
     */
    @Bean
    public AutoLoginInterceptor autoLoginInterceptor() {
        return new AutoLoginInterceptor();
    }

    @Override
    // 添加自定义拦截器
    public void addInterceptors(InterceptorRegistry registry) {
        // 自动登录拦截器
        registry.addInterceptor(autoLoginInterceptor()).excludePathPatterns("/assets/**", "/favicon.ico", "/verify/**");
        // 自动全局Session注入拦截器
        registry.addInterceptor(new SessionInterceptor());
        registry.addInterceptor(new MoAuthInterceptor()).addPathPatterns("/mojie/**");
        registry.addInterceptor(new MoStateCheckInterceptor()).addPathPatterns("/mojie/**");
        super.addInterceptors(registry);
    }

    @Override
    // 排除静态资源拦截
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/resources/")
                .addResourceLocations("classpath:/static/")
                .addResourceLocations("classpath:/public/");
        // 将 static目录 映射到 /目录
        registry.addResourceHandler("/assets/**").addResourceLocations("classpath:/static/", "classpath:/META-INF/resources/");
        super.addResourceHandlers(registry);
    }
}
